layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    $(function () {
        function initWxShare() {
            var parameName='code'
            var parameValue=''
            var parames = window.location.search
            if (parames.indexOf(parameName) > -1) {
                // var parameValue = ''
                parameValue = parames.substring(parames.indexOf(parameName), parames.length)
                if (parameValue.indexOf('&') > -1) {
                    parameValue = parameValue.substring(0, parameValue.indexOf('&'))
                    parameValue = parameValue.replace(parameName + '=', '')

                }

            }


            var code = parameValue
            var localurl = window.location.href
            var goback = encodeURIComponent(localurl)
            // console.log(window.location.href)
            // Feng.success(window.location.href);
            var appid = 'wx6e61dcacc7980e43'
            var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + goback + '&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect'
            //var url='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5f3a575e5a1d7875&redirect_uri=http%3A%2F%2Fmini.huobanban.com.cn%2F%3Fcode%3D091Wrjll2VHdc74VbQol2C5Tbs2Wrjlf%26state%3Dstate%23%2Fmyauth&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect'

            if (!code) {
                location.href = url
            }
            var data = {
                code: code
            }

            var ajax = new $ax(Feng.ctxPath + "/flowWxMember/getOfficeUnionid", function (data) {
                // Feng.success("删除成功!");
                alert("绑定成功")
                // console.log("ssssssss")

            }, function (data) {
                Feng.error("绑定失败!" + data.responseJSON.message + "!");
            });
            ajax.set("code", data.code);
            ajax.start();

            // var ajaxurl = $("#ApiUrl").val()+"?url=" + link;
            // var ajaxurl='http://localhost/flowWxMember/getOfficeUnionid'
            // $.ajax({
            //     url: ajaxurl,
            //     type: "POST",
            //     data:data,
            //     dataType: "json",
            //     success: function (ress) {
            //         console.log(ress);
            //         alert("绑定成功")
            //         // wx.ready(function () {
            //         //
            //         // })
            //     },
            //     error: function (ress) {
            //         console.log("通信失败:"+ress);
            //     }
            // })
        }
        initWxShare();
    })
});
